package com.elitetyc.eliteim.client.command.impl;

import cn.hutool.json.JSONUtil;
import com.elitetyc.eliteim.common.constant.Constants;
import com.elitetyc.eliteim.common.model.impl.U2UMsg;
import com.elitetyc.eliteim.common.util.MsgUtil;
import com.elitetyc.eliteim.client.EliteIMClient;
import com.elitetyc.eliteim.client.command.InnerCommand;
import com.elitetyc.eliteim.client.command.anno.Command;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author yuanchao.tan
 * @version 1.0
 * @description
 * @Date 2021/9/17 14:31
 */
@Command(command = ":u",desc = "对指定用户发送消息")
public class User2UserInnerCommand implements InnerCommand {

    @Autowired
    private EliteIMClient eliteIMClient;

    @Override
    public void process(String msg) {
        final String[] split = msg.split(" ");
        final String receiveUserId = split[1];
        final String content = split[2];
        U2UMsg u2UMsg = MsgUtil.buildU2UStrMsg(receiveUserId,content);
        MsgUtil.echoMsg(String.format("你对用户【%s】说：%s",receiveUserId,content));
        eliteIMClient.sendMsg(MsgUtil.buildMsg(Constants.RequestType.U2U, JSONUtil.toJsonStr(u2UMsg)));

    }
}
